<template>
    <div class='comment'>

        <el-dialog title="详细评论" :visible.sync="dialogVisible" width="90%" @close="handleClose">
            <el-table :data="tableData" style="width: 100%">
                <el-table-column prop="id" label="评论ID" width="50">
                </el-table-column>
                <el-table-column prop="username" label="评论用户">
                </el-table-column>
                <el-table-column prop="nickname" label="评论人">
                </el-table-column>
                <el-table-column prop="content" label="评论内容" width="180" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="like" label="点赞数">
                </el-table-column>
                <el-table-column prop="othernick" label="回复对象">
                </el-table-column>
                <el-table-column prop="parentid" label="评论文章id">
                </el-table-column>
                <el-table-column prop="time" label="评论时间" width="200">
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="100">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="onDelete(scope.row.id)">删除评论</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>

            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                :page-sizes="[5, 10, 15, 20]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'comment-page',
    data() {
        return {
            dialogVisible: false,
            id: '',
            url: {
                list: '/comment/detail',
                delete: '/comment/delete'
            },
            tableData: [],
            limit: 5,
            page: 1,
            total: 0
        };
    },
    created() {

    },
    methods: {
        open(id) {
            this.id = id
            this.getDataList()
            this.dialogVisible = true
        },
        getDataList() {
            this.$http.get(this.url.list, {
                params: {
                    parentid: this.id,
                    limit:this.limit,
                    page:this.page
                }
            }).then(res => {
                console.log('res', res)
                this.total = res.data.total
                this.tableData = res.data.results
            })
        },
        handleClose() {
            this.$emit('close')
        },
        //删除评论
        onDelete(id) {
            this.$http.post(this.url.delete, {
                id
            }).then(res => {
                console.log(res);
                if (res && res.status == 200) {
                    this.$message({
                        message: '删除成功',
                        type: 'success'
                    });
                    this.getDataList()
                }
            })
        },
        handleSizeChange(val) {
            console.log(val);
            this.limit = val
            this.getDataList()
        },
        handleCurrentChange(val) {
            console.log(val);
            this.page = val
            this.getDataList()
        }
    }
}
</script>

<style scoped lang='less'></style>